#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

typedef char* String;

String players[] = {
    "Havi",
    "Old Jiang",
    "Old Yang",
    "Young Yang",
    "Messi10",
    "Nima",
    "Kun",
    "Manager Stone",
    "Sea",
    "Big Master",
    "Club Barcelona",
    "Grandpa Eight",
    "Big Hair",
    "Small New",
    NULL
};

typedef struct players{
    String *plys;
    int *randnum;
} Players;

int getPlayerNum(String *pstr)
{
    int num = 0;
    while (*pstr != NULL){
        num++;
        pstr++;
    }
    return num;    
}

void printPlayers(Players player)
{
    String *p = player.plys;
    int *randnum = player.randnum;
    int i = 0;
    int a,b;
    int size = getPlayerNum(p);
    a = size / 2;
    b = size;
    printf("Group A (%d players):\n", a);
    for(; i < a; i++){        
        printf("%s, ", *(p + *(randnum + i)));
    }
    printf("\nGroup B (%d players):\n", b - a);
    for(; i < b; i++){        
        printf("%s, ", *(p + *(randnum + i)));
    }
}

int *randPlayer(int size)
{
    int i = 0, j = 0, cnt = 0;
    char n;
    int *pNum = (int *)malloc(size * sizeof(int));
    memset(pNum, 0xFF, size * sizeof(int));
    srand((unsigned) time(NULL));
    while (1){
        n = rand() % size;
        for(i = 0, cnt = 0; i < size; i++){
            if(n != pNum[i]){
                cnt++;
            }           
        }
        if(cnt == size){
            pNum[j++] = n;            
            if(j == size)
                break;
        }
    } 
    return pNum;  
}

int main(void)
{
    Players pls = {players, randPlayer(getPlayerNum(players))};    
    printPlayers(pls);
    return 0;
}